home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / language / awe / awe-full.lha / Awe2 / DoNotUseThisSrc / MultiCpuMuxExceptions.cc < prev    next >
C/C++ Source or Header  |  1990-08-08  |  2KB  |  87 lines

  1. // This may look like C code, but it is really -*- C++ -*-
  2. // 
  3. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  4. //
  5. // written by Dirk Grunwald (grunwald@cs.uiuc.edu)
  6. //
  7.  
  8. #ifdef __GNUG__
  9. #  pragma implementation
  10. #endif
  11.  
  12. #include "MultiCpuMuxExceptions.h"
  13. #include "ReserveByException.h"
  14. #include "CpuMultiplexor.h"
  15. #include "HardwareContextP.h"
  16. #include "MultiCpuMux.h"
  17. #include "SpinBarrier.h"
  18. #include "stream.h"
  19. #include "Thread.h"
  20.  
  21. void
  22. ExceptionRelocate::handleException()
  23. {
  24.     MultiCpuMux *cpu = (MultiCpuMux *) ThisCpu;
  25.     //
  26.     // Switch to another thread when we havenot gotten
  27.     // rid of the current one.
  28.     //
  29. #ifndef NDEBUG
  30.     if (cpu -> debug()) {
  31.     CpuCerrLock.reserve();
  32.     cerr << cpu -> name() << " reschedule exception to ";
  33.     cerr << newCpu << "\n";
  34.     CpuCerrLock.release();
  35.     }
  36. #endif /* NDEBUG */
  37.  
  38.     assert(cpu -> currentThread != 0);
  39.     cpu -> addToAnother(newCpu, cpu -> currentThread );
  40.     cpu -> currentThread = 0;
  41. }
  42.  
  43. //
  44. //    Used to add or remove CPUs from the current pool of CPUs
  45. //
  46.  
  47. static SpinBarrier TwoCpuBarrier(2);
  48.  
  49. void
  50. ExceptionEnrollDismissCpu::handleException()
  51. {
  52.     MultiCpuMux *cpu = (MultiCpuMux *) ThisCpu;
  53.     if (enrollOrDismiss) {
  54.     //
  55.     // enroll
  56.     //
  57.     assert( cpu -> cpuId() == 0 );
  58.     //
  59.     //
  60.     // Now fork the child. We need to insure that the new child
  61.     // and the parent leave only after the data structures have been
  62.     // created, otherwise barriers in subclasses may have problems.
  63.     //
  64.     int pid = fork();
  65.     if ( pid == 0 ) {
  66.         cpu -> iYam = CpuMultiplexors;
  67.         //
  68.         // CpuMux::allocateEventStructures will set CpuMultiplexors
  69.         //
  70.         cpu -> allocateEventStructures(cpu -> iYam,
  71.                            CpuMultiplexors+1 );
  72.         //
  73.         // cause child to schedule new process at stirItAround
  74.         //
  75.         cpu -> currentThread = 0;
  76.         cpu -> pid = getpid();
  77.     }
  78.     TwoCpuBarrier.rendezvous();
  79.     }
  80.     else {
  81.     //
  82.     // dismiss
  83.     //
  84.     assert( 0 );
  85.     }
  86. }
  87.